package com.wowangz.cms.common.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * 用于数据比较
 * @author leiyang3
 *
 */
public class DataCompare {
	
	/**
	 * 比较两个日期的大小
	 * 如果相等返回0
	 * 如果d1大于d2返回1
	 * 如果d1小于d2返回-1
	 * @param d1
	 * @param d2
	 * @return
	 */
	public static int compareDate(Date d1, Date d2) throws Exception {
		if(d1 == null || d2 == null){
			throw new Exception("日期不能为空");
		}
		
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(d1);
		cal1.set(Calendar.HOUR_OF_DAY, 0);
		cal1.set(Calendar.MINUTE, 0);
		cal1.set(Calendar.SECOND, 0);
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(d2);
		cal2.set(Calendar.HOUR_OF_DAY, 0);
		cal2.set(Calendar.MINUTE, 0);
		cal2.set(Calendar.SECOND, 0);
		
		return cal1.compareTo(cal2);
	}

	
	
}
